<?php

require '../Control_BD/conectar.php';
session_start();

$username = trim($_POST['matricula']);
$password = trim($_POST['contrasena']);
$tipo = $_POST['tipo'];
if($tipo == "xyz"){
    $tipo=2;
}else if($tipo == "zyx"){
    $tipo=1;
}else{
    $tipo = 0;
}
$password=md5($password);

$usernameDefault = 'admin';
$passwordDefault = 'admin';


$queryVal = "select num_cliente,tipo,confirmacion_mail from cliente where mail = '$username' and password = '$password' and tipo='$tipo'";
$resultVal=mysql_fetch_array(mysql_query($queryVal));

require '../Control_BD/desconectar.php';

if ($resultVal) {
    
    $_SESSION["num_cliente"] = $resultVal['num_cliente'];
    $_SESSION["usuario"] = $resultVal['num_cliente'];
    $_SESSION["mail"] = $username;
    
    if($resultVal['tipo'] == 1){
        $_SESSION["tipo"] = "admin";
    }else if($resultVal['tipo'] == 2){
        $_SESSION["tipo"] = "cliente";
    }
    
    $_SESSION["confirmado"] = $resultVal['confirmacion_mail'];
    
    if($resultVal['tipo'] == 1){
        header('Location: http://www.thepool.vg/Pruebas/intranet/portal/');
    }else{
        header('Location: http://www.thepool.vg/Pruebas/resumen-de-compras/');
    }
    
    
    exit;
} else {
    echo "<script type=\"text/javascript\">
        alert (\"Nombre de usuario o contraseña incorrectos.\");
        window.history.back(-1);
        </script>";
}

?>
